package net.betou.common.security.encoder;

import java.util.UUID;

import org.apache.commons.lang.StringUtils;

/**
 * UUID生成器
 * @author 叶装装
 *
 */
public class UUIDSaltGenerator implements SaltGenerator{

	public String randomSalt( ) {
		return subStringUUID( UUID.randomUUID( ) );
	}

	public String saltFromBytes( byte [ ] bytes ) {
		return subStringUUID( UUID.nameUUIDFromBytes( bytes ) );
	}

	public String saltFromString( String s ) {
		return saltFromBytes( s.getBytes( ) );
	}

	private String subStringUUID( UUID uuid ) {
		return StringUtils.split( uuid.toString( ), "-" )[ 0 ];
	}
}
